home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
Pete Johnson
/
mehit 3.0.b15<source>.cpt
/
Help.p
< prev
next >
Wrap
Text File
|
1991-06-22
|
6KB
|
227 lines
unit Help;
interface
procedure Help (strRsrcNum, hlpRsrcNum: Integer);
implementation
type
TopicSet = record
textRsrc, stylRsrc: Integer;
end;
HelpListHdl = ^HelpListPtr;
HelpListPtr = ^HelpList;
HelpList = record
numTopics: Integer;
topicSets: array[0..0] of TopicSet;
end;
var
myDialog: DialogPtr;
myHelpListH: HelpListHdl;
theList: ListHandle;
pagesize, numTopics: Integer;
textRes, numTopicsH: Handle;
sBar: ControlHandle;
theText: TEHandle;
procedure CreateList (strRsrcNum: integer);
var
i, iType: Integer;
topicStr: Str255;
iRect, dataBounds: Rect;
cSize, theCell: Cell;
iHandle: Handle;
begin
GetDItem(myDialog, 3, iType, iHandle, iRect);
FrameRect(iRect);
InsetRect(iRect, 1, 1);
SetPt(cSize, iRect.right - iRect.left, 17);
SetRect(dataBounds, 0, 0, 1, numTopics);
theList := LNew(iRect, dataBounds, cSize, 0, myDialog, False, False, False, True);
for i := 1 to numTopics do {drawIt, hasGrow, hScroll, vScroll}
begin
GetIndString(topicStr, strRsrcNum, i);
SetPt(theCell, 0, i - 1);
LSetCell(Pointer(Ord(@topicStr) + 1), Length(topicStr), theCell, theList);
end;
theList^^.selFlags := lOnlyOne;
SetPt(theCell, 0, 0);
LSetSelect(true, theCell, theList);
LDoDraw(True, theList); {set drawing to True now that list is built}
end;
procedure ScrAction (theCtl: ControlHandle; partCode: Integer);
var
delta, oldValue: Integer;
begin
case partCode of
inUpButton:
delta := -10;
inDownButton:
delta := 10;
inPageUp:
delta := -pagesize;
inPageDown:
delta := pagesize;
otherwise
end;
if partCode <> 0 then
begin
oldValue := GetCtlValue(theCtl);
SetCtlValue(theCtl, oldValue + delta);
TEScroll(0, oldValue - GetCtlValue(theCtl), theText);
end;
end;
procedure WindowScroll (thePt: Point; theWindow: WindowPtr);
var
theCtl: ControlHandle;
part, oldValue: Integer;
begin
GlobalToLocal(thePt);
case FindControl(thePt, theWindow, theCtl) of
inUpButton..inPageDown:
part := TrackControl(theCtl, thePt, @ScrAction);
inThumb:
begin
with theText^^ do
oldValue := viewRect.top - destRect.top;
if TrackControl(theCtl, thePt, nil) <> 0 then
TEScroll(0, oldValue - GetCtlValue(theCtl), theText);
end;
otherwise
end;
end;
procedure LoadText (item: Integer);
const
inactive = 255;
var
max, textNum, stylNum: Integer;
textRes, stylRes: Handle;
begin
TEDeactivate(theText);
TESetSelect(0, 32767, theText);
TEDelete(theText);
theText^^.destRect := theText^^.viewRect;
textNum := myHelpListH^^.topicSets[item].textRsrc;
stylNum := myHelpListH^^.topicSets[item].stylRsrc;
if (textNum <> 0) & (stylNum <> 0) then
begin
textRes := GetResource('TEXT', textNum);
stylRes := GetResource('styl', stylNum);
HLock(textRes);
HLock(stylRes);
TEStylInsert(textRes^, SizeResource(textRes), StScrpHandle(stylRes), theText);
HUnlock(stylRes);
HUnlock(textRes);
end;
max := TEGetHeight(theText^^.nLines, 0, theText) - pagesize;
if max > 0 then
HiliteControl(sBar, activeFlag)
else
HiliteControl(sBar, inactive);
SetCtlValue(sBar, 0);
SetCtlMax(sBar, max);
TEActivate(theText);
end;
function MyFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: Integer): Boolean;
var
iType, part: Integer;
iBox: Rect;
iHdl: Handle;
thePt: Point;
theCtl: ControlHandle;
ignore: Boolean;
newCell: Cell;
begin
MyFilter := False;
case theEvent.what of
keyDown, autoKey: {close if enter or return is keyed}
if BitAnd(theEvent.message, charCodeMask) in [3, 13] then
begin
MyFilter := True;
GetDItem(theDialog, 1, iType, iHdl, iBox);
InvertRoundRect(iBox, 10, 10);
itemHit := 1;
end;
mouseDown:
begin
thePt := theEvent.where;
GlobalToLocal(thePt);
part := FindControl(thePt, myDialog, theCtl);
if theCtl = sBar then
WindowScroll(theEvent.where, myDialog)
else if theCtl = theList^^.vScroll then
ignore := LClick(thePt, theEvent.modifiers, theList)
else if PtInRect(thePt, theList^^.rView) then
begin
ignore := LClick(thePt, theEvent.modifiers, theList);
SetPt(newCell, 0, 0);
ignore := LGetSelect(True, newCell, theList);
LoadText(newCell.v);
end;
end;
updateEvt:
begin
TEUpdate(theText^^.viewRect, theText);
LUpdate(myDialog^.visRgn, theList);
end;
otherwise
end;
end;
procedure Help; {(strRsrcNum, hlpRsrcNum: Integer)}
type
IntHdl = ^IntPtr;
IntPtr = ^Integer;
var
savePort: GrafPtr;
iBox, tBox: Rect;
iType, itemHit: Integer;
iHdl: Handle;
begin
GetPort(savePort);
myDialog := GetNewDialog(257, nil, Pointer(-1));
SetPort(myDialog);
DrawDialog(myDialog);
TextFont(0);
TextSize(12);
numTopics := IntHdl(GetResource('STR#', strRsrcNum))^^;
myHelpListH := HelpListHdl(GetResource('HLP#', hlpRsrcNum));
HLock(Handle(myHelpListH));
CreateList(strRsrcNum);
GetDItem(myDialog, 2, iType, iHdl, tBox);
FrameRect(tBox);
InsetRect(tBox, 4, 2);
pagesize := tBox.bottom - tBox.top;
theText := TEStylNew(tBox, tBox);
HLock(Handle(theText));
GetDItem(myDialog, 6, iType, iHdl, iBox);
sBar := ControlHandle(iHdl);
GetDItem(myDialog, 1, iType, iHdl, iBox);
InsetRect(iBox, -4, -4);
PenSize(3, 3);
FrameRoundRect(iBox, 16, 16);
PenSize(1, 1);
LoadText(0);
repeat
ModalDialog(@MyFilter, itemHit);
DrawDialog(myDialog);
until itemHit = 1;
HUnlock(Handle(theText));
LDispose(theList);
Hunlock(Handle(myHelpListH));
DisposDialog(myDialog);
SetPort(savePort);
end;
end.